﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;

using System.Windows.Forms;

namespace Atentis_Connector
{
	public partial class MoneyControlForm : Form
	{
		private MoneyControl m_MoneyControl;
		public MoneyControlForm()
		{
			InitializeComponent();
		}

		public MoneyControlForm(MoneyControl moneyControl)
		{
			InitializeComponent();

			txtProfit.Text = moneyControl.p_Profit.ToString();
			txtLoss.Text = moneyControl.p_Loss.ToString();
			txtDeltaProfitLine.Text = moneyControl.p_DeltaProfitLine.ToString();
			txtDeltaProfit.Text = moneyControl.p_DeltaProfit.ToString();
			txtReturnSlide.Text = moneyControl.p_ReturnSlide.ToString();
			txtVolume.Text = moneyControl.p_Volume.ToString();
			txtStepVolume.Text = moneyControl.p_StepVolume.ToString();
			txtStepCount.Text = moneyControl.p_StepCount.ToString();
			txtStepDelta.Text = moneyControl.p_StepDelta.ToString();
		}

		/// <summary>
		/// Событие - обновлены настройки стратегии
		/// </summary>
		public event EventHandler MoneyControlSettingsUpdated;

		void OnMoneyControlSettingsUpdated(AtentisConnectorEventArgs e)
		{
			EventHandler moneyControlSettingsUpdated = MoneyControlSettingsUpdated;
			if (moneyControlSettingsUpdated != null)
				moneyControlSettingsUpdated(this, e);
		}

		private void AcceptButton_Click(object sender, EventArgs e)
		{
			try
			{
				m_MoneyControl = new MoneyControl();
				string strProf = txtProfit.Text.Replace('.', ',');
				string strLoss = txtLoss.Text.Replace('.', ',');

				m_MoneyControl.F_SetSettings(
					Convert.ToDouble(strProf),
					Convert.ToDouble(strLoss),
					Convert.ToInt32(txtDeltaProfitLine.Text),
					Convert.ToInt32(txtDeltaProfit.Text),
					Convert.ToInt32(txtReturnSlide.Text),
					Convert.ToInt32(txtVolume.Text),
					Convert.ToInt32(txtStepVolume.Text),
					Convert.ToInt32(txtStepCount.Text),
					Convert.ToInt32(txtStepDelta.Text)
					);
				var acea = new AtentisConnectorEventArgs(m_MoneyControl);
				OnMoneyControlSettingsUpdated(acea);
				Close();
			}
			catch
			{
				
			}
		}
	}
}
